<!--- =================================================================================================================================
	*
	*
	*
	*
	*
	*
	  ================================================================================================================================= --->
<cfcomponent output="false">
	<cfscript>

		/**
		* 	Constructor Method
		* 	@name constructor
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-17
		*	@return Void
		**/
		public Void function constructor() {

			variables.factory 			= Application.instance.factory;
			variables.error 			= variables.factory.getModels("Error");
			variables.cast				= variables.factory.getCore("Cast");
			this.instance.problemData 	= "";
			this.instance.adapter		= "";
			this.instance.orderParam	= "";
			this.instance.operation		= "";
		}

		/**
		* 	Domain manipulation Method
		* 	@name select
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-17
		*	@return Domain
		**/
		public Domain function select( Any val = "" , Any argument = "" ) {

			if( CompareNoCase( arguments.val , "" ) == 0 ) {
				if( CompareNoCase( this.instance.problemData , "" ) == 0 ) {
					variables.error.handlerError( Application.config.customExceptionUser ,"The object data is required to solve some problem" );
				}
			}
			else {
				this.instance.problemData = arguments.val;
			}

			this.instance.adapter = this.getAdapter();

			this.instance.problemData = this.instance.adapter.select( this.instance.problemData , arguments.argument );

			return this;
		}

		/**
		* 	Domain manipulation Method
		* 	@name and
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-21
		*	@return Domain
		**/
		public Domain function and( Any argument ) {
			return this.select( arguments.argument );
		}

		/**
		* 	Domain random Method
		* 	@name random
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-21
		*	@return Domain
		**/
		public Domain function random( Query val = "" ) {

			if( CompareNoCase( arguments.val , "" ) == 0 ) {
				if( CompareNoCase( this.instance.problemData , "" ) == 0 ) {
					variables.error.handlerError( Application.config.customExceptionUser ,"The object data is required to solve some problem" );
				}
			}
			else {
				this.instance.problemData = arguments.val;
			}

			this.instance.adapter = this.getAdapter();

			this.instance.problemData = this.instance.adapter.random( this.instance.problemData );

			return this;
		}

		/**
		* 	Domain sort Method
		* 	@name asc
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-21
		*	@return Domain
		**/
		public Domain function asc( String field ) {
			if( CompareNoCase( this.instance.problemData , "" ) == 0 ) {
				variables.error.handlerError( Application.config.customExceptionUser ,"The object data is required to solve some problem" );
			}
			else {
				this.instance.adapter = this.getAdapter();

				if( IsQuery( this.instance.problemData ) == true ) {
					this.instance.orderParam = ListAppend( this.instance.orderParam , this.instance.adapter.asc( field : arguments.field ) );
				}
				else {
					this.instance.orderParam = this.instance.adapter.asc( field : arguments.field );
				}
			}
		}

		/**
		* 	Domain sort Method
		* 	@name desc
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-21
		*	@return Domain
		**/
		public Domain function desc( String field ) {
			if( CompareNoCase( this.instance.problemData , "" ) == 0 ) {
				variables.error.handlerError( Application.config.customExceptionUser ,"The object data is required to solve some problem" );
			}
			else {
				this.instance.adapter = this.getAdapter();

				if( IsQuery( this.instance.problemData ) == true ) {
					this.instance.orderParam = ListAppend( this.instance.orderParam , this.instance.adapter.desc( field : arguments.field ) );
				}
				else {
					this.instance.orderParam = this.instance.adapter.desc( field : arguments.field );
				}
			}
		}

		/**
		* 	Domain sort data Method
		* 	@name sort
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-29
		*	@return Query
		**/
		public Domain function sort( Query recordSet ) {
			if( CompareNoCase( this.instance.problemData , "" ) == 0 ) {
				variables.error.handlerError( Application.config.customExceptionUser ,"The object data is required to solve some problem" );
			}
			else {
				this.instance.adapter = this.getAdapter();

				try{
					if( Len( this.instance.orderParam ) > 0 ) {
						this.instance.adapter.sort( recordSet : this.instance.problemData , field : this.instance.orderParam );
					}
					else {
						variables.error.handlerError( Application.config.customExceptionUser , "To sort an object, is necessary ordering the object before, use asc ou desc methos before sort method" );
					}
				}
				catch( Any Ex ) {
					variables.error.handlerError( Application.config.customExceptionUser , Ex.message );
				}
			}

			return this;
		}

		/**
		* 	Domain apply operator function Method
		* 	@name operator
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-21
		*	@return Void
		**/
		public Void function operator( String argument ) {
			this.instance.adapter = this.getAdapter();
<<<<<<< HEAD
			this.instance.operation = ListAppend( this.instance.operation ,
												  this.instance.adapter.operator( arguments.argument ) ,
												  this.instance.adapter.getOperationDelimiter()
												);
=======
			this.instance.operation = ListAppend( this.instance.operation , 
												  this.instance.adapter.operator( arguments.argument ) , 
												  this.instance.adapter.getOperationDelimiter() );
>>>>>>> branch 'master' of https://andersonstraube@code.google.com/p/cold-weld/
		}

		/**
		* 	cast data to array Method
		* 	@name asArray
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-22
		*	@return Domain
		**/
		public Domain function asArray( Any val ) {
			this.instance.problemData = variables.cast.asArray( data : arguments.val );

			return this;
		}

		/**
		* 	cast data to query Method
		* 	@name asQuery
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-25
		*	@return Domain
		**/
		public Domain function asQuery( Any val ) {
			this.instance.problemData = variables.cast.asQuery( data : arguments.val );

			return this;
		}

		/**
		* 	get an item of object Method
		* 	@name getItem
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-22
		*	@return Domain
		**/
		public Domain function getItem( String field , Any item = "" ) {
			this.instance.adapter 		= this.getAdapter();
			this.instance.problemData 	= this.instance.adapter.getItem( data : this.instance.problemData , field : arguments.field , item : arguments.item );

			return this;
		}

		/**
		* 	set data in object Method
		* 	@name add
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-28
		*	@return Domain
		**/
		public Domain function add( Any val ) {
			var adapter	= variables.factory.getDitionary("ArrayDriver");

			return adapter.add( source : this.instance.problemData , data : arguments.val );
		}

		/**
		* 	sum data from some attribute object Method
		* 	@name sumFrom
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-29
		*	@return Domain
		**/
		public Domain function sumFrom( Any val ) {
			var adapter	= this.getAdapter();

			return adapter.sumFrom( source : this.instance.problemData , data : arguments.val );
		}

		/**
		* 	Domain get adapter intance Method
		* 	@name getAdapter
		* 	@access public
		* 	@author Paulo Teixeira
		*	@date 2012-05-21
		*	@return AdapterInstance
		**/
		private Any function getAdapter() {
			if( CompareNoCase( this.instance.problemData , "" ) == 0 ) {
				variables.error.handlerError( Application.config.customExceptionUser ,"The object data is required to solve some problem" );
			}
			else {
				if( IsArray( this.instance.problemData ) == true ) {
					return variables.factory.getDitionary("ArrayDriver");
				}
				else if( IsQuery( this.instance.problemData ) == true ) {
					return variables.factory.getDitionary("QueryDriver");
				}
				else if( IsStruct( arguments.problemData ) == true ) {
					return variables.factory.getDitionary("StructDriver");
				}
				else if( ListLen( arguments.problemData ) gt 0 ) {
					return variables.factory.getDitionary("ListDriver");
				}
				else {
					variables.error.handlerError( Application.config.customExceptionUser , "The object data not is in a valid data type or is empty" );
				}
			}
		}

	</cfscript>
</cfcomponent>
